﻿namespace HuwmanCode.ServiceProcess

open System
open System.Diagnostics
open System.ServiceProcess

///<summary>
/// Specifies the WindowsService dependency on another service
///</summary>
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)>]
type public DependsOnAttribute(serviceName:String) =
    inherit Attribute()

    new (service:Type) = new DependsOnAttribute(service.FullName)
    
    member internal x.ServiceName
        with get() = serviceName

    static member GetDependencies(instance) =
        instance.GetType().GetCustomAttributes(typeof<DependsOnAttribute>, false)
        |> Array.map(fun o -> o :?> DependsOnAttribute)
        |> Array.map(fun a -> a.ServiceName)
